package com.songshuai.webapi.baseapi.enumerations.sales.error;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum SopError {


    ERROR_SOP_ID_NOT_EXIST(1,"SOP记录不存在"),
    ERROR_SOP_LABEL_NOT_NULL(2,"SOP标签不能为空"),
    ERROR_SOP_GROUP_NOT_NULL(3,"SOP适用人群不能为空"),
    ERROR_SOP_SUBTYPE_NOT_NULL(4,"SOP子分类不能为空"),
    ERROR_SOP_SOPTYPE_NOT_NULL(5,"SOP类型不能为空"),
    ERROR_SOP_TITLE_NOT_NULL(6,"SOP标题不能为空"),
    ERROR_SOP_IMG_NOT_NULL(7,"SOP图片地址不能为空"),
    ERROR_SOP_CONTENT_NOT_NULL(8,"SOP内容不能为空"),
    ERROR_SOP_VIDEO_KEY_NOT_NULL(9,"SOP视频KEY不能为空"),
    ERROR_SOP_ID_NOT_NULL(10,"SOPID不能为空"),
    ERROR_SOP_HOTNUM_NOT_NULL(11,"SOP热度值不能为空"),
    ERROR_SOP_PUBLISHTIME_NOT_NULL(12,"SOP发布时间不能为空"),
    ERROR_SOP_TOPENDTIME_NOT_NULL(13,"SOP结束置顶时间不能为空"),
    ERROR_SOP_RECIVEUSERS_NOT_NULL(14,"SOP接受人不能为空"),
    ERROR_SOP_VIEWID_NOT_NULL(15,"SOP浏览记录ID不能为空"),
    ERROR_SOP_VIEWID_NOT_EXIST(16,"SOP浏览记录ID不存在"),
    ERROR_SOP_OPERATION_STATUS_NOT_NULL(17,"SOP操作状态不能为空"),
    ERROR_SOP_SAME_TITLE_IS_EXIST(18,"发布标题重复"),
    ERROR_SOP_DESCRIPTION_NOT_NULL(19,"SOP描述不能为空");






    private int code;
    private String msg;

    SopError(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return SopError.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return SopError.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(SopError err : SopError.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
